# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: server\routers\__init__.py
__author__ = "sanyi"
import logging
from server.http_responses.http_errors import RouteNotFound

logger = logging.getLogger("server.router")


class Router:
    RESPONSE_TYPE = None

    def __init__(self, base_path=None, host=None, methods=None, schemes=None):
        self._base_path = base_path
        self._host = host
        self._methods = set(methods) if methods else None
        self._schemes = set(schemes) if schemes else None
        self._len_base_path = len(base_path) if base_path is not None else 0

    def filter(self, scheme, host, method, path):
        if self._host:
            if host != self._host:
                raise RouteNotFound()
        if self._schemes:
            if scheme not in self._schemes:
                raise RouteNotFound()
        if self._methods:
            if method not in self._methods:
                raise RouteNotFound()
        if self._base_path:
            if not path.startswith(self._base_path):
                raise RouteNotFound()

    def handle_request(self, method, scheme, path, environment, start_response):
        raise NotImplementedError()

    @property
    def base_path(self):
        return self._base_path

    @property
    def host(self):
        return self._host

    @property
    def schemes(self):
        return self.schemes

    @property
    def methods(self):
        return self._methods
